package com.rm.zeyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rm.zeyou.entity.ApplicationConfig;
import com.rm.zeyou.entity.DictConfig;
import com.rm.zeyou.mapper.ApplicationConfigMapper;
import com.rm.zeyou.mapper.DictConfigMapper;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.DictConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 系统参数配置 服务实现类
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:08
 */
@Service
public class DictConfigServiceImpl extends ServiceImpl<DictConfigMapper, DictConfig> implements DictConfigService {
    @Resource
    private ApplicationConfigMapper applicationConfigMapper;

    @Override
    public ApiRestResponse<Map<String, String>> downAddress() {
        Map<String, String> map = new HashMap<>(3);
        ApplicationConfig downloadAndroid = applicationConfigMapper.selectOne(new LambdaQueryWrapper<ApplicationConfig>().eq(ApplicationConfig::getCode, "user_download_android"));
        ApplicationConfig technicianDownloadAndroid = applicationConfigMapper.selectOne(new LambdaQueryWrapper<ApplicationConfig>().eq(ApplicationConfig::getCode, "technician_download_android"));
        ApplicationConfig downloadIos = applicationConfigMapper.selectOne(new LambdaQueryWrapper<ApplicationConfig>().eq(ApplicationConfig::getCode, "user_download_ios"));
        ApplicationConfig technicianDownloadIos = applicationConfigMapper.selectOne(new LambdaQueryWrapper<ApplicationConfig>().eq(ApplicationConfig::getCode, "technician_download_ios"));
        ApplicationConfig downloadVersion = applicationConfigMapper.selectOne(new LambdaQueryWrapper<ApplicationConfig>().eq(ApplicationConfig::getCode, "user_app_version"));
        ApplicationConfig technicianAppVersion = applicationConfigMapper.selectOne(new LambdaQueryWrapper<ApplicationConfig>().eq(ApplicationConfig::getCode, "technician_app_version"));
        map.put("android", downloadAndroid.getValue());
        map.put("ios", downloadIos.getValue());
        map.put("version", downloadVersion.getValue());
        map.put("technicianDownloadAndroid", technicianDownloadAndroid.getValue());
        map.put("technicianDownloadIos", technicianDownloadIos.getValue());
        map.put("technicianAppVersion", technicianAppVersion.getValue());
        return ApiRestResponse.success(map);
    }
}
